#include <cstdio>
#include <queue>
#include <iostream>
#include <algorithm>
using namespace std;
priority_queue <int,vector<int>,greater<int> > qe;
int main()
{
	int n,k,num;
	char c;
	while(scanf("%d %d",&n,&k)!=EOF)
	{
		while(!qe.empty())
		{
			qe.pop();
		}
		for(int i=0;i<n;i++)
		{
			scanf(" %c",&c);
			if(c=='I')
			{
				scanf("%d",&num);
				if(qe.size()<k)
				{
					qe.push(num);
				}
				else
				{
					if(num>qe.top())
					{
						qe.pop();
						qe.push(num);
					}
				}
			}
			else 
			{
				printf("%d\n",qe.top());
			}
		}
	}
	
	
}
